/*
* 简单线程池设计
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>

typedef struct _tNode{
void * (*task_func)(void *);
void * arg;
struct _tpool * next;
}tNode;

typedef struct _tPool{
    int off;
    int max_thread_num;
    pthread_t * tid;
    tNode * task_queue_head;
    pthread_cond_t queue_ready;
    pthread_mutex_t queue_lock;
}tPool;

int create_pool(tPool ** pool, int max_thread_num);

int destroy_pool(tPool * pool);

int add_task(tPool * pool, void * (*task)(void*), void * arg);

void * run_task(void * pool);

void lamport_lock(int id);

void lamport_unlock(int id);